<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

// 加载Doctrine 库
require_once APPPATH.'/helpers/doctrine/lib/Doctrine.php';

// 从codeigniter加载数据库配置
require_once APPPATH.'/config/database.php';

//允许Doctrine自动加载Model类
spl_autoload_register(array('Doctrine', 'autoload'));

// 数据库连接加载到 Doctrine_Manager
// 这个循环允许我们使用多个连接
foreach ($db as $connection_name => $db_values) {

	// 首先我们必须转换dsn格式
	$dsn = $db[$connection_name]['dbdriver'] .
		'://' . $db[$connection_name]['username'] .
		':' . $db[$connection_name]['password'].
		'@' . $db[$connection_name]['hostname'] .
		'/' . $db[$connection_name]['database'];

	Doctrine_Manager::connection($dsn,$connection_name);
}

// 需要加载Codeigniter的模型类
require_once BASEPATH.'core/Model.php';

// 告诉 Doctrine 我们模型的位置
Doctrine::loadModels(APPPATH.'/models');

// (可选) 下列配置

// 这将允许我们使用“存取器”（mutators）
Doctrine_Manager::getInstance()->setAttribute(
	Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);

// this sets all table columns to not null and unsigned (for ints) by default
Doctrine_Manager::getInstance()->setAttribute(
	Doctrine::ATTR_DEFAULT_COLUMN_OPTIONS,
	array('notnull' => true, 'unsigned' => true));

// 设置默认主键为 'id', 整型, 4 bytes
Doctrine_Manager::getInstance()->setAttribute(
	Doctrine::ATTR_DEFAULT_IDENTIFIER_OPTIONS,
	array('name' => 'id', 'type' => 'integer', 'length' => 20));

Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_RESULT_CACHE_LIFESPAN, 30);

# 设置softdelete后,对查询语句进行回调处理
Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_USE_DQL_CALLBACKS, true);

/* End of file */